//
//  String+Regex.swift
//  KeepCliming
//
//  Created by 鱼龙之梦 on 15/9/20.
//  Copyright © 2015年 panyanzhi. All rights reserved.
//

import Foundation

extension String {
    func href()->(link:String,text:String)?{
        let pattern = "<a href=\"(.*?)\".*?>(.*?)</a>"
        let regex = try! NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions.DotMatchesLineSeparators)
        guard let result = regex.firstMatchInString(self, options: [], range: NSRange(location: 0, length: self.characters.count)) else {
            return nil
        }
        let link = (self as NSString).substringWithRange(result.rangeAtIndex(1))
        let text = (self as NSString).substringWithRange(result.rangeAtIndex(2))
        return (link,text)
    }
}
